<template>
  <div class="bigBox">
    <div class="back">
      <a-button class="button" @click="goBack" type="link" block :icon="h(ArrowLeftOutlined)">
        返回
      </a-button>
      <div class="search" v-if="!$route.query.id">
        <a-input-search allowClear style="width: 300px" v-model:value="keyword" placeholder="请输入关键词搜索" enter-button
          @search="getSearch(1, 10)" @change="onChange" />
      </div>
    </div>
    <div class="keyword" v-if="!$route.query.id && keyword == ''">
      <h2>今日热搜</h2>
      <div class="hotSearch">
        <div v-for="item in hots" @click="clickKeyword(item)">{{ item }}</div>
      </div>
    </div>
    <div class="boxImg" ref="boxImg" v-else>
      <photo-provider :default-backdrop-opacity="0.5">
        <div class="everyBox" v-for="item in classif">
          <photo-consumer style="width: 100%" :intro="item.utag" :src="item.img_1600_900 || item.url">
            <img v-lazy="item.img_1600_900 || item.url" alt="" />
          </photo-consumer>
          <div class="tag">
            <a-tag v-for="(tag, i) in computerTag(item.utag)" v-show="tag" :color="computerColor(i)"
              style="margin-top: 5px">
              {{ tag }}
            </a-tag>
          </div>
          <div class="operation">
            <a-button type="primary" size="small" @click="setBackImg(item.img_1600_900 || item.url)">
              设为壁纸
            </a-button>
          </div>
        </div>
      </photo-provider>
    </div>
    <vxe-pager class="footer" background v-model:current-page="page" v-model:page-size="count" :total="total"
      @page-change="onChange" :page-sizes="[10, 20, 30, 50]" :layouts="[
        'PrevJump',
        'PrevPage',
        'JumpNumber',
        'NextPage',
        'NextJump',
        'Sizes',
        'FullJump',
        'Total',
      ]"></vxe-pager>
  </div>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router'
import { onMounted, h } from 'vue'
import { ArrowLeftOutlined } from '@ant-design/icons-vue'
import imageHK from '@/hooks/image'

const onChange = (obj: any) => {
  $route.query.id
    ? getImg(obj.currentPage, obj.pageSize)
    : getSearch(obj.currentPage, obj.pageSize)
}
const {
  page,
  count,
  classif,
  keyword,
  $route,
  hots,
  total,
  getSearch,
  todayHotSearch,
  getImg,
  computerTag,
  computerColor,
  setBackImg,
  clickKeyword,
} = imageHK()
const $router = useRouter()
const goBack = () => {
  $router.go(-1)
}

onMounted(() => {
  if ($route.query.id) {
    getImg(1, 10)
  } else {
    todayHotSearch()
  }
})
</script>

<style lang="scss" scoped>
.bigBox {
  height: 100vh;
  background-color: white;

  .back {
    position: sticky;
    top: 0;
    background: linear-gradient(to bottom,
        rgba(0, 0, 0, 0),
        rgba(172, 214, 255, 0.5) 80%),
      linear-gradient(to right, rgb(40, 148, 255), rgba(210, 233, 255, 0.5));
    padding: 5px;
    z-index: 10;
    margin-bottom: 5px;
    box-shadow: 0 0 5px 0px var(--themeColor);
    display: grid;
    grid-template-columns: 150px 1fr;

    .button {
      width: 100px;
      font-weight: bold;
      color: white;

      &:hover {
        color: var(--themeColor);
      }
    }

    .search {
      text-align: right;
    }
  }

  .keyword {
    h2 {
      margin: 30px 0 10px 0;
      padding-left: 10px;
    }

    .hotSearch {
      display: flex;
      flex-wrap: wrap;

      div {
        margin: 10px 5px;
        padding: 5px 10px;
        cursor: pointer;
        color: rgb(71, 61, 61);
        background-color: rgba(128, 128, 128, 0.1);
        border-radius: 5px;
        transition: all 0.3s;

        &:hover {
          color: white;
          background-color: var(--themeColor);
        }
      }
    }
  }

  .boxImg {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 10px;
    padding-bottom: 60px;
    max-height: calc(100% - 80px);
    overflow-y: scroll;
    @include scroll_bar();
    padding-left: 8px;

    .everyBox {
      border-radius: 5px;
      box-shadow: 1px 2px 10px rgba(128, 128, 128, 0.5);
      position: relative;
      transition: all 0.5s;

      .operation {
        position: absolute;
        top: 0;
        right: 0;
        z-index: 10;
        display: none;
      }

      &:hover {
        .operation {
          display: block;
        }

        box-shadow: 0 0 5px var(--themeColor);
      }

      img {
        width: 100%;
        max-height: 250px;
        cursor: pointer;
        transition: all 0.5s;

        &:hover {
          scale: 0.96;
        }
      }

      .tag {
        padding: 5px;
      }
    }
  }

  .footer {
    position: fixed;
    bottom: 0;
    width: 100%;
    text-align: center;
    padding: 10px 0;
  }
}


.more {
  padding: 10px;
  position: fixed;
  bottom: 30px;
  right: 30px;

  div {
    height: 40px;
    width: 40px;
    text-align: center;
    line-height: 40px;
    margin: 10px 0;
    border-radius: 50%;
    cursor: pointer;
    border-radius: 50px;
    background: white;
    font-weight: bold;
    box-shadow:
      6px 6px 13px #bebebe,
      -6px -6px 13px #ffffff;
    color: blue;
    transition: all 0.5s;

    &:hover {
      color: white;
      background-color: var(--themeColor);
    }
  }
}
</style>
